/*
 *	Copyright (c) 2009, libBasement
 *	All rights reserved.
 *	
 *	Redistribution and use in source and binary forms, with or without modification,
 *	are permitted provided that the following conditions are met:
 *	
 *	Redistributions of source code must retain the above copyright notice,
 *	this list of conditions and the following disclaimer.
 *	Redistributions in binary form must reproduce the above copyright notice,
 *	this list of conditions and the following disclaimer in the documentation
 *	and/or other materials provided with the distribution.
 *	Neither the name of the <ORGANIZATION> nor the names of its contributors may
 *	be used to endorse or promote products derived from this software without
 *	specific prior written permission.
 *	THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 *	AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 *	THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 *	ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
 *	FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 *	(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 *	LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 *	ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *	(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 *	SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#include <BObject.h>
#include <cstring>

#ifndef BString_h
#define BString_h 1

namespace Basement
{
	String *$(String *string);
	String *$(const char *cString);
	String *$s(String *string);
	String *$s(const char *cString);
	
	class String : public Object
	{
	protected:
		std::string _string;
		
	public:
		__BObjectStandardFunctions(String)
		
		virtual String *description() { return this; }
		
		static String *withString(String *other);
		static String *withStdString(std::string &string);
		static String *withCString(const char *cString);
		static String *withStrings(String *string, ...);
		
		virtual String *init();
		virtual String *initWithString(String *other);
		virtual String *initWithStdString(std::string &string);
		virtual String *initWithCString(const char *cString);
		virtual String *initWithStrings(String *string, ...) __attribute__((sentinel));
		virtual String *initWithStrings(String *string, va_list arguments);
		
		virtual UInteger length() const;
		virtual char characterAtIndex(UInteger index) const;
		virtual const char *getCString() const;
		virtual std::string getStdString() const;
		
		virtual char *getCharactersInRange(Range range) const;
		virtual char *copyCString() const;
		
		virtual bool hasPrefix(String *other) const;
		virtual bool hasSuffix(String *other) const;
		virtual bool isEqualToString(String *other);
		virtual bool isEqualTo(String *other) { return this->isEqualToString(other); };
		
		virtual String *stringByAppendingString(String *otherString) const;
		virtual String *appendString(String *otherString);
		
		virtual String *replaceCharactersInRange(Range range, String *otherString);
		virtual String *deleteCharactersInRange(Range range);
		virtual String *replaceOccurrencesOfStringWithString(String *needle, String *replacement);
		
		virtual String *substringWithRange(Range range) const;
		virtual String *substringToIndex(UInteger index) const;
		virtual String *substringFromIndex(UInteger index) const;
	};
}

#endif /* BString_h */
